//
//  BlurEffectViewController.m
//  myDemo2
//
//  Created by wuxueying on 5/14/14.
//
//

#import "BlurEffectViewController.h"
#import "UIImage+ImageEffects.h"

@interface BlurEffectViewController () {
    BOOL isBlur;
}
@property (weak, nonatomic) IBOutlet UIImageView *blurImage;
@end
@implementation BlurEffectViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (IBAction)blur:(id)sender {
    isBlur = !isBlur;
    if (isBlur) {
        _blurImage.image = [UIImage imageNamed:@"2.jpg"];
    }else {
        UIGraphicsBeginImageContextWithOptions(CGSizeMake(CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)), NO, 1);
        [self.view drawViewHierarchyInRect:CGRectMake(0, 0, CGRectGetWidth(self.view.frame), CGRectGetHeight(self.view.frame)) afterScreenUpdates:NO];
        __block UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
            dispatch_sync(dispatch_get_main_queue(), ^{
                snapshot = [snapshot applyExtraLightEffect];
                self.blurImage.image = snapshot;
            });
        });
    }
}

@end
